package com.yty.controller;


import com.yty.pojo.ClazzCountOption;
import com.yty.pojo.JobOption;
import com.yty.pojo.Result;
import com.yty.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RequestMapping("/report")
@RestController
public class ReprotController {

     @Autowired
     private ReportService reportService;

    @GetMapping("/empJobData")
    public Result getEmpJobData()
    {
        List<Map<String, Object>> empJobData = reportService.getEmpJobData();
        List<Object> jobList = empJobData.stream().map(jobData -> {
            return jobData.get("job");
        }).toList();
        List<Object> dataList = empJobData.stream().map(jobData -> {
            return jobData.get("num");
        }).toList();
        log.info("查询所有部门信息成功:{}", empJobData);
        return Result.success(new JobOption(jobList, dataList));
    }
    @GetMapping("/empGenderData")
    public Result getEmpGenderData()
    {
        List<Map<String, Object>> empGenderData = reportService.getEmpGenderData();
        log.info("查询所有部门信息成功:{}", empGenderData);
        return Result.success(empGenderData);
    }

    @GetMapping("/studentDegreeData")
    public Result getStudentDegreeData(){
        List<Map<String, Object>> studentDegreeData = reportService.getStudentDegreeData();
        log.info("查询所有学生学历信息统计成功:{}", studentDegreeData);
        return Result.success(studentDegreeData);
    }

    @GetMapping("/studentCountData")
    public Result getStudentCountData(){
        List<Map<String, Object>> studentCountData = reportService.getStudentCountData();
        log.info("查询所班级统计信息成功:{}", studentCountData);
        List<Object> clazzList = studentCountData.stream().map(studentData -> {
            return studentData.get("name");
        }).toList();
        List<Object> dataLis = studentCountData.stream().map(studentData -> {
            return studentData.get("value");
        }).toList();
        return Result.success(new ClazzCountOption(clazzList, dataLis));
    }
}
